import request from 'umi-request';

export async function getLeaveList(params) {
  return request('/api/member/api-member/memberLeave/getMemberLeaveList', {
    method: 'post',
    data:{
      pageNum: params.current,
      pageSize: params.pageSize,
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function saveOrUpdateLeaveInfo(params) {
  return request('/api/member/api-member/memberLeave/saveOrUpdateLeave', {
    method: 'POST',
    data: {
      ...params,
    },
  }).then((res) => {
    return res;
  });
}

export async function sendLeaveBpm(id) {
  return request('/api/member/api-member/bpm/leaveBpm', {
    method: 'POST',
    data: {
      id:id
    },
    requestType: 'form'
}).then((res) => {
    return res;
  });
}

export async function deleteLeave(id) {
  return request(`/api/member/api-member/memberLeave/deleteLeave`, {
    method: 'delete',
    params: {
      id: id
    }
  }).then((res) => {
    return res;
  });
}

export async function getResidueDay() {
  return request('/api/member/api-member/memberLeave/getResidueDay', {
    method: 'POST',
  }).then((res) => {
    return res.data;
  });
}

export async function getRealLeaveDay(params) {
  return request('/api/member/api-member/memberLeave/getRealLeaveDay', {
    method: 'POST',
    data:{
      ...params
    }
  }).then((res) => {
    return res.data;
  });
}


export async function getMemberDistributeLeaveList(params) {
  return request('/api/member/api-member/memberLeave/getMemberDistributeLeaveList', {
    method: 'post',
    data:{
      pageNum: params.current,
      pageSize: params.pageSize,
    },
    requestType: 'form'
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function saveOrUpdateDistributeLeave(params) {
  return request('/api/member/api-member/memberLeave/saveOrUpdateDistributeLeave', {
    method: 'POST',
    data: {
      ...params,
    },
  }).then((res) => {
    return res;
  });
}

export async function deleteDistributeLeave(id) {
  return request(`/api/member/api-member/memberLeave/deleteDistributeLeave`, {
    method: 'delete',
    params: {
      id: id
    }
  }).then((res) => {
    return res;
  });
}

export async function distributeBmp(id) {
  return request('/api/member/api-member/bpm/distributeBmp', {
    method: 'POST',
    data: {
      id:id
    },
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function getMemberHolidayList(params) {
  return request('/api/member/api-member/reportBack/listReport', {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getReportBackFrequency(oid) {
  return request('/api/member/api-member/reportBack/getReportBackFrequency', {
    method: 'get',
    params: {oid:oid},
  }).then((res) => {
    return res.data;
  });
}

export async function saveOrEditReportBack(params) {
  return request('/api/member/api-member/reportBack/saveReportBack', {
    method: 'POST',
    data: {
      ...params,
    },
  }).then((res) => {
    return res;
  });
}

export async function deleteReportBack(id) {
  return request(`/api/member/api-member/reportBack/deleteReportBack`, {
    method: 'delete',
    params: {
      id: id
    }
  }).then((res) => {
    return res;
  });
}

export async function reportBackBpm(id) {
  return request('/api/member/api-member/bpm/reportBackBpm', {
    method: 'POST',
    data: {
      id:id
    },
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}
